package com.markedquilt.comment.coomon;

import org.springframework.validation.BindingResult;
import org.springframework.validation.FieldError;

/**
 * @author ZhangKe
 * @Description
 * @date 2020/4/19 12:22.
 */
public class CommonUtil {
    public static String processErrorString(BindingResult bindingResult){
        if (!bindingResult.hasErrors()){
            return "";
        }
        StringBuilder stringBuilder=new StringBuilder();
        for (FieldError fieldError:bindingResult.getFieldErrors()){
            stringBuilder.append(fieldError.getDefaultMessage()+",");
        }
        return stringBuilder.substring(0,stringBuilder.length()-1);
    }
}
